//所有接口封装

var interface_config = require('/interfaceConfig.js')
var primise = require('/utils/primiseUtils.js')

/**
 * 获取轮播图信息
 * 
*/
function SlideImgs() {
    console.log("获取头部轮播图");
    var data = {};
    var url = interface_config.SlideImgs;
    return primise.postRequest(data, url);
}

/**
 * 获取正在热映电影
 * GetAllCinemaHotFilms
 * @param String jingdu 经度
 * @param String  weidu 纬度
 * @param string areasId 地区编号
*/
function GetAllCinemaHotFilms(jingdu, weidu, cinemaId) {

    console.log("get获取热映");
    var data = {
        jingdu: jingdu,
        weidu: weidu,
        cinemaId: cinemaId
    };
    var url = interface_config.GetAllCinemaHotFilms;
    return primise.getRequest(data, url);
}



/**
 * 即将上映
 * GetAllCinemaUpcomingFilms
 * @param string areasId 地区编号 
 *
*/
function GetAllCinemaUpcomingFilms(cinemaId) {
    console.log("获取即将上映");
    var data = {
        cinemaId: cinemaId
    };
    var url = interface_config.GetAllCinemaUpcomingFilms;
    return primise.getRequest(data, url);
}

/**
 * 点击想看
 * @param string filmId 电影编号
 * @param string miniAppOpenId  openid
 * 
*/
function LikeToSee(filmId, miniAppOpenId) {
    console.log("点击想看");
    var data = {
        filmId: filmId,
        miniAppOpenId: miniAppOpenId
    };
    var url = interface_config.LikeToSee;
    return primise.postRequest(data, url);
}

/**
 * 获取电影院
 * @param string jingdu 经度
 * @param string weidu  纬度
 * 
*/

function GetCinemaByMovieId(jingdu, weidu) {
    console.log("选择影院");
    var data = {
        jingdu: jingdu,
        weidu: weidu,
    };
    var url = interface_config.GetCinemaByMovieId;
    return primise.getRequest(data, url);
}

/**
 * 登录 
 * @param code 
 * 
*/
function MiniAppLogin(code) {
    console.log("登录");
    var data = {
        code: code,

    };
    var url = interface_config.MiniAppLogin;
    return primise.getRequest(data, url);
}


/**
 * 注册 
 * @param unionid 
 * @param openid
 * @param phone
 * @param code 手机验证码
 * 
 * 
*/
function MiniAppRegister(code, phone, phoneCode) {
    console.log("注册");
    var data = {
        code: code,
        phone: phone,
        phoneCode: phoneCode
    };
    var url = interface_config.MiniAppRegister;
    return primise.getRequest(data, url);
}





/**
 * 获取签名
 * @param paramstring 
 * 
*/
function GetSignStr(paramstring) {
    console.log("获取签名");
    var data = {
        paramstring: paramstring,

    };
    var url = interface_config.GetSignStr;
    return primise.getRequest(data, url);
}

/**
 * 发送验证码
 * @param phone 
 * 
*/
function SendSms(phone) {
    console.log("短信验证");
    var data = {
        phone: phone,

    };
    var url = interface_config.SendSms;
    return primise.getRequest(data, url);
}

/**
 * 获取电影列表
 * @param string strAppCode, 程序码
 * @param string CinemaCode 影院code
 * @param string PlayDate, 上映日期一般为今天
* @param string sign 签名
 * 
*/
function GetFilmLis(strAppCode, CinemaCode, PlayDate, sign) {
    console.log("获取电影列表");
    var data = {
        strAppCode: strAppCode,
        CinemaCode: CinemaCode,
        PlayDate: PlayDate,
        sign: sign
    };
    var url = interface_config.GetFilmLis;
    return primise.getRequest(data, url);
}

/**
 * 获取日期
 * @param  string strAppCode,
 * @param string CinemaCode,
 * @param string FilmCode, 影片编码
 * @param string PlayStartDate,传空值""
 * @param string PlayEndDate, 传空值""
 * @param string sign
 * 
*/
function GetPlanDateList(strAppCode, CinemaCode, FilmCode, PlayStartDate, PlayEndDate, sign) {
    console.log("获取电影日期");
    var data = {
        strAppCode: strAppCode,
        CinemaCode: CinemaCode,
        FilmCode: FilmCode,
        PlayStartDate: PlayStartDate,
        PlayEndDate: PlayEndDate,
        sign: sign
    };
    var url = interface_config.GetPlanDateList;
    return primise.getRequest(data, url);
}

/**
 *strAppCode
  CinemaCode
  FilmCode=
  PlayStartDate=
  PlayEndDate=
  sign=
 *
 * 
*/
function GetPlanList(strAppCode, CinemaCode, FilmCode, PlayStartDate, PlayEndDate, sign) {
    console.log("获取电影日期");
    var data = {
        strAppCode: strAppCode,
        CinemaCode: CinemaCode,
        FilmCode: FilmCode,
        PlayStartDate: PlayStartDate,
        PlayEndDate: PlayEndDate,
        sign: sign
    };
    var url = interface_config.GetPlanList;
    return primise.getRequest(data, url);
}
/**
 * string strAppCode
    string CinemaCode
    string PlanCodeApp
      string sign
 * */
function GetSeatMap(strAppCode, CinemaCode, PlanCodeApp, sign) {
    console.log("获取粗图");
    var data = {
        strAppCode: strAppCode,
        CinemaCode: CinemaCode,
        PlanCodeApp: PlanCodeApp,
        sign: sign
    };
    var url = interface_config.GetSeatMap;
    return primise.getRequest(data, url);
}

/**
string strAppCode
string CinemaCode
string PlanCodeApp
,string sign
 * */
function GetPlanSiteState(strAppCode, CinemaCode, PlanCodeApp, sign) {
    console.log("获取细图");
    var data = {
        strAppCode: strAppCode,
        CinemaCode: CinemaCode,
        PlanCodeApp: PlanCodeApp,
        sign: sign
    };
    var url = interface_config.GetPlanSiteState;
    return primise.getRequest(data, url);
}

/**
 * string strAppCode
string AddTypeID
string FeatureAppNo
 string PriceTotal
string SeatInfo
string UserID
string PayPhone
 string sign
 * */
function LockSeat(strAppCode, AddTypeID, FeatureAppNo, PriceTotal, SeatInfo, UserID, PayPhone, sign, token) {
    console.log("锁定作为");
    var data = {
        strAppCode: strAppCode,
        AddTypeID: AddTypeID,
        FeatureAppNo: FeatureAppNo,
        PriceTotal: PriceTotal,
        SeatInfo: SeatInfo,
        UserID: UserID,
        PayPhone: PayPhone,
        sign: sign
    };
    var url = interface_config.LockSeat;
    return primise.getlgRequest(data, url, token);
}

/**
 string strAppCode
 string sign
 * */
function GetGoodList(strAppCode, sign) {
    console.log("获取商品");
    var data = {
        strAppCode: strAppCode,
        sign: sign
    };
    var url = interface_config.GetGoodList;
    return primise.getRequest(data, url);
}

/**
string strAppCode, string OrderTicketID, string GoodsInfo, string sign
 * */
function SaveOrderGoods(strAppCode, AddTypeID, FeatureAppNo, PriceTotal, SeatInfo, UserID, PayPhone, EventID, OrderSource, EventDiscountTotal, Num, GoodsInfo, sign, token) {
    console.log("提交商品");
    var data = {
        strAppCode: strAppCode,
        AddTypeID: AddTypeID,
        FeatureAppNo: FeatureAppNo,
        PriceTotal: PriceTotal,
        SeatInfo: SeatInfo,
        UserID: UserID,
        PayPhone: PayPhone,
        EventID: EventID,
        OrderSource: OrderSource,
        EventDiscountTotal: EventDiscountTotal,
        Num: Num,
        GoodsInfo: GoodsInfo,
        sign: sign,
    };
    var url = interface_config.SaveOrderGoods;
    return primise.getlgRequest(data, url, token);
}

/**
 * string strAppCode
string OrderTicketID
string sign
 * */
function GetOrderDetailList(strAppCode, OrderTicketID, sign, token) {
    console.log("获取订单");
    var data = {
        strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        sign: sign,
    };
    var url = interface_config.GetOrderDetailList;
    return primise.getlgRequest(data, url, token);
}

/**
 string strAppCode,
 string OrderTicketID,
 string wxopenID
string TelCode,
string sign
 * */
function mberAccount(strAppCode, OrderTicketID, sign, token) {
    console.log("会员卡信息");
    var data = {
        strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        sign: sign,
    };
    var url = interface_config.mberAccount;
    return primise.getlgRequest(data, url, token);
}

/*
tring strAppCode,
string OrderTicketID,
 string wxopenID,
 string mphone,
string strCardNo,
 string LinkTelcode,
 string coupons,
 string PayTotalPrice,
 string sign

**/

function SellTicketA(strAppCode, OrderTicketID, wxopenID, mphone, strCardNo, LinkTelcode, coupons, PayTotalPrice, sign, token) {
    console.log("会员卡支付");
    var data = {
        strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        wxopenID: wxopenID,
        mphone: mphone,
        strCardNo: strCardNo,
        LinkTelcode: LinkTelcode,
        coupons: coupons,
        PayTotalPrice: PayTotalPrice,
        sign: sign,
    };
    var url = interface_config.SellTicketA;
    return primise.getlgRequest(data, url, token);
}

function SellTicketB(strAppCode, OrderTicketID, wxopenID, mphone, LinkTelcode, pamounts, coupons, sign, token) {
    var data = {
        strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        wxopenID: wxopenID,
        mphone: mphone,
        LinkTelcode: LinkTelcode,
        pamounts: pamounts,
        coupons: coupons,
        sign: sign,
    };
    var url = interface_config.SellTicketB;
    return primise.getlgRequest(data, url, token);
}

function GetUserInfo(token) {
    var app = getApp();
    token = app.globalData.token;
    console.log("获取用户信息");
    var data = {
    };
    var url = interface_config.GetUserInfo;
    return primise.getlgRequest(data, url, token);
}

function GetAndSetUserInfo(token) {
    var app = getApp();
    token = app.globalData.token;
    var data = {
    };
    var url = interface_config.GetUserInfo;
    primise.getlgRequest(data, url, token).then(result => {
        if (result.data.success) {
            app.globalData.loginuserinfo = result.data.data // res.data.data
            console.log("app.globalData.loginuserinfo");
            console.log(app.globalData.loginuserinfo);
            return;
        }
    });
}

function ActivityGoodsList(Activitytype, Page, Pagesize, tagid, CinemaCode) {
    console.log(CinemaCode)
    var data = {
        Activitytype: Activitytype,
        page: Page,
        pagesize: Pagesize,
        tagid: tagid,
        CinemaCode: CinemaCode
    };
    var url = interface_config.ActivityGoodsList;
    var token = "";
    return primise.getlgRequest(data, url, token);
}


function GoodsDetail(id) {
    var data = {
        Eventid: id
    };
    var url = interface_config.GoodsDetail;
    var token = "";
    return primise.getlgRequest(data, url, token);
}





function GetGiftRecord(token) {
    var data = {
    };
    var url = interface_config.GetGiftRecord;
    return primise.getlgRequest(data, url, token);
}


function GetGift(id, token) {
    var data = {
        id: id
    };
    var url = interface_config.GetGift;
    return primise.getlgRequest(data, url, token);
}


function VipQrcode(token) {
    var data = {
    };
    var url = interface_config.VipQrcode;
    return primise.getlgRequest(data, url, token);
}


function VipPayList(token) {
    var data = {
    };
    var url = interface_config.VipPayList;
    return primise.getlgRequest(data, url, token);
}

function VipPay(id, token) {
    var data = {
        id: id
    };
    var url = interface_config.VipPay;
    return primise.getlgRequest(data, url, token);
}


function GetModiPwdMsg(mobile, token) {
    var data = { mobile: mobile, };
    var url = interface_config.GetModiPwdMsg;
    return primise.getlgRequest(data, url, token);
}

function ModiPwd(mobile, code, pwd, token) {
    var data = { mobile: mobile, code: code, pwd, pwd };
    var url = interface_config.ModiPwd;
    return primise.getlgRequest(data, url, token);
}

function MyCouponList(token) {
    var data = {
    };
    var url = interface_config.MyCouponList;
    return primise.getlgRequest(data, url, token);
}

function FeedBack(content, token) {

    var data = {
        content: content
    };
    var url = interface_config.FeedBack;
    return primise.getlgRequest(data, url, token);
}

function PointsList(pageIndex, pageSize, token) {
    var data = {
        pageIndex: pageIndex,
        pageSize: pageSize
    };
    var url = interface_config.PointsList;
    return primise.getlgRequest(data, url, token);
}

function BillsList(pageIndex, pageSize, token) {
    var data = {
        pageIndex: pageIndex,
        pageSize: pageSize
    };
    var url = interface_config.BillsList;
    return primise.getlgRequest(data, url, token);
}



function BillDetails(id, types, token) {
    var data = {
        id: id,
        type: types
    };
    var url = interface_config.BillDetails;
    return primise.getlgRequest(data, url, token);
}


function getOrderList(strAppCode, UserID, PayMobile, StartDate, EndDate, OrderType, sign, token) {
    var data = {
        strAppCode: strAppCode,
        UserID: UserID,
        PayMobile: PayMobile,
        StartDate: StartDate,
        EndDate: EndDate,
        OrderType: OrderType,
        sign: sign
    };
    var url = interface_config.getOrderList;
    return primise.getlgRequest(data, url, token);
}


function GetAllOrderList(strAppCode, page, pagesize, OrderSource, StartDate, EndDate, OrderType, sign, token) {
    var data = {
        strAppCode: strAppCode,
        page: page,
        pagesize: pagesize,
        OrderSource: OrderSource,
        StartDate: StartDate,
        EndDate: EndDate,
        OrderType: OrderType,
        sign: sign
    };
    var url = interface_config.GetAllOrderList;
    return primise.getlgRequest(data, url, token);
}


function vipBind(vipNum, phone, phoneCode, token) {
    var data = {
        vipNum: vipNum,
        phone: phone,
        phoneCode: phoneCode
    };
    var url = interface_config.vipBind;
    return primise.getlgRequest(data, url, token);
}

function UnBind(id, token) {
    var data = {
        id: id,
    };
    var url = interface_config.UnBind;
    return primise.getlgRequest(data, url, token);
}

function CardList(token) {
    var data = {

    };
    var url = interface_config.CardList;
    return primise.getlgRequest(data, url, token);
}

function MyCouponList2(token) {
    var data = {};
    var url = interface_config.MyCouponList2;
    return primise.getlgRequest(data, url, token);
}
function VipPayListDetails(token, id) {
    var data = {
        id: id
    };
    var url = interface_config.VipPayListDetails;
    return primise.getlgRequest(data, url, token);
}

function SendVipBindSms(phone, token) {
    var data = {
        phone: phone
    };
    var url = interface_config.SendVipBindSms;
    return primise.getlgRequest(data, url, token);
}

function GetGiftList(token) {
    var data = {

    };
    var url = interface_config.GetGiftList;
    return primise.getlgRequest(data, url, token);
}


function GetMiniAppPaySign(strAppCode, OrderTicketID, wxopenID,
    mphone, LinkTelcode, pamounts, coupons, sign, token
) {
    var data = {
        strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        wxopenID: wxopenID,
        mphone: mphone,
        LinkTelcode: LinkTelcode,
        pamounts: pamounts,
        coupons: coupons,
        sign: sign

    };
    var url = interface_config.GetMiniAppPaySign;
    return primise.getlgRequest(data, url, token);
}


//活动卖品 - 会员卡支付

// 1 OrderTicketID 主订单ID String NOT NULL 
// 2 OrderGoodsDetailID 详细订单ID String NOT NULL 
// 3 wxopenID openid String NOT NULL 
// 4 mphone 会员手机号 String NOT NULL 
// 5 LinkTelcode 购买手机号 String NOT NULL 
// 6 coupons 优惠券编号 String NOT NULL 使用的优惠券编号，多个优惠券中间用, 分隔
// 7 PayTotalPrice 会员卡支付金额 String NOT NULL 使用优惠券后，会员卡还需要支付的总金额
// 8 sign String NOT NULL 

function ActivityGoodsOrder(OrderTicketID, OrderGoodsDetailID, wxopenID, mphone, LinkTelcode, coupons, PayTotalPrice, sign, token) {
    var data = {
        OrderTicketID: OrderTicketID,
        OrderGoodsDetailID: OrderGoodsDetailID,
        wxopenID: wxopenID,
        mphone: mphone,
        LinkTelcode: LinkTelcode,
        coupons: coupons,
        PayTotalPrice: PayTotalPrice,
        sign: sign
    };
    var url = interface_config.ActivityGoodsOrder;
    return primise.getlgRequest(data, url, token);
}


//活动卖品微信支付
function GetMiniGoodsAppPaySign(OrderTicketID, OrderGoodsDetailID,
    LinkTelcode, coupons, PayTotalPrice, sign, token) {
    var data = {
        // strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        OrderGoodsDetailID: OrderGoodsDetailID,
        LinkTelcode: LinkTelcode,
        PayTotalPrice: PayTotalPrice,
        coupons: coupons,
        sign: sign

    };
    var url = interface_config.GetMiniGoodsAppPaySign;
    return primise.getlgRequest(data, url, token);
}


//活动电影 会员卡支付


/**
 * OrderTicketID 主订单ID String NOT NULL
  wxopenID openid String NOT NULL
  mphone 会员手机号 String NOT NULL
  LinkTelcode 购买手机号 String NOT NULL
  coupons 优惠券编号 String NOT NULL 使用的优惠券编号，多个优惠券中间用,分隔  活动不能使用优惠卷
PayTotalPrice 会员卡支付金额 String NOT NULL 使用优惠券后，会员卡还需要支付的总金额
 * 
 * */
function ActivFilmOrdB(OrderTicketID, wxopenID, mphone, LinkTelcode, coupons, PayTotalPrice, token) {
    var data = {
        // strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        wxopenID: wxopenID,
        mphone: mphone,
        LinkTelcode: LinkTelcode,
        coupons: coupons,
        PayTotalPrice: PayTotalPrice,
        // sign: sign
    };
    var url = interface_config.ActivFilmOrdB;
    return primise.getlgRequest(data, url, token);
}


function GetMiniFlimAppPaySign(OrderTicketID, pamounts, coupons, token) {
    var data = {
        // strAppCode: strAppCode,
        OrderTicketID: OrderTicketID,
        pamounts: pamounts,
        coupons: coupons,
    };
    var url = interface_config.GetMiniFlimAppPaySign;
    return primise.getlgRequest(data, url, token);
}


/**
 * EventDiscountTarget 活动类型
 * EventDiscountType   活动对象
 * EventDiscountValue     折扣金额
 * PriceService  服务费
 * tickcount   票个
 * PriceSale  票价
 * EventDiscountThreshold  订单满减
*/
//计算价格
function CalculateActivityPrice(EventDiscountTarget, EventDiscountType, EventDiscountValue, PriceService, tickcount, PriceSale, EventDiscountThreshold) {
    var data = {
        // strAppCode: strAppCode,
        EventDiscountTarget: EventDiscountTarget,
        EventDiscountType: EventDiscountType,
        EventDiscountValue: EventDiscountValue,
        PriceService: PriceService,
        tickcount: tickcount,
        PriceSale: PriceSale,
        EventDiscountThreshold: EventDiscountThreshold
    };
    var url = interface_config.CalculateActivityPrice;
    var token = "";
    return primise.getlgRequest(data, url, token);
}

function ActivityFilmDetail(id) {
    var data = {
        Eventid: id
    };
    var url = interface_config.ActivityFilmDetail;
    var token = "";
    return primise.getlgRequest(data, url, token);
}

//TODO活动锁座
// AddTypeID 接入类型 Int NOT NULL 
// FeatureAppNo 排期编码 String NOT NULL 
// PriceTotal 订单价格 String NOT NULL （票价 + 服务费）*数量
// SeatInfo 座位信息 String NOT NULL 
// UserID 用户ID Int NOT NULL 
// PayPhone 支付手机号 String NOT NULL

function SaveLockEvent(AddTypeID, FeatureAppNo, PriceTotal, SeatInfo, UserID, PayPhone, EventId, NumLimit, OrderDetail
) {
    var data = {
        AddTypeID: AddTypeID,
        FeatureAppNo: FeatureAppNo,
        PriceTotal: PriceTotal,
        SeatInfo: SeatInfo,
        UserID: UserID,
        PayPhone: PayPhone,
        EventId, EventId,
        NumLimit: NumLimit,
        OrderDetail: OrderDetail

    };
    var url = interface_config.SaveLockEvent;
    var token = "";
    return primise.getlgRequest(data, url, token);
}

function LockCheck(rows_cels, graphcels) {
    var data = {
        rows_cels: rows_cels,
        graphcels: graphcels,

    };
    var url = interface_config.LockCheck;
    var token = "";
    return primise.getlgRequest(data, url, token);
}

function FilmDetail(FilmCode, EventId){
  var data = {
    FilmCode: FilmCode,
    EventId: EventId,

  };
  var url = interface_config.FilmDetail;
  var token = "";
  return primise.getlgRequest(data, url, token);
}



module.exports = {
  SlideImgs: SlideImgs,
  GetAllCinemaHotFilms: GetAllCinemaHotFilms,
  GetAllCinemaUpcomingFilms: GetAllCinemaUpcomingFilms,
  LikeToSee: LikeToSee,
  GetCinemaByMovieId: GetCinemaByMovieId,
  MiniAppLogin,
  MiniAppRegister,
  GetSignStr,
  SendSms,
  GetFilmLis,
  GetPlanDateList,
  GetPlanList,
  GetSeatMap,
  GetPlanSiteState,
  LockSeat,
  GetGoodList,
  SaveOrderGoods,
  GetOrderDetailList,
  mberAccount,
  SellTicketA,
  GetUserInfo,
  ActivityGoodsList,
  GoodsDetail,
  GetGiftRecord,
  GetGift,
  VipQrcode,
  VipPayList: VipPayList,
  VipPay: VipPay,
  GetModiPwdMsg: GetModiPwdMsg,
  ModiPwd: ModiPwd,
  MyCouponList: MyCouponList,
  FeedBack: FeedBack,
  PointsList: PointsList,
  BillsList: BillsList,
  BillDetails: BillDetails,
  GetAllOrderList,
  vipBind,
  UnBind,
  CardList,
  SendVipBindSms,
  GetGiftList,
  GetMiniAppPaySign,
  GetMiniGoodsAppPaySign,
  ActivityGoodsOrder,
  GetMiniFlimAppPaySign,
  CalculateActivityPrice,
  ActivityFilmDetail,
  SaveLockEvent,
  LockCheck,
  getOrderList,
  ActivFilmOrdB,
  VipPayListDetails,
  MyCouponList2,
  SellTicketB,
  FilmDetail,
  GetAndSetUserInfo
}